import { defineStore } from 'pinia'
import { getConfig } from '~~/api/app'
import {getdecorate} from '~~/api/index'
interface AppSate {
    config: Record<string, any>
}
export const useAppStore = defineStore({
    id: 'appStore',
    state: (): AppSate => ({
        config: {},
        bg:{}
    }),
    getters: {
        getDrawingBg: (state) => state.bg.drawing.url || {},
        getUserInfoBg: (state) => state.bg['user-info'].url || {},
        getUserDrawingBg: (state) => state.bg['user-drawing'].url || {},
        getVipBg: (state) => state.bg.vip.url || {},
        getCardCodeConfig: (state) => state.config.cardCode || {},
        getChatConfig: (state) => state.config.chat || {},
        getWebsiteConfig: (state) => state.config.website || {},
        getCopyrightConfig: (state) => state.config.copyright || {},
        getBulletinConfig: (state) => state.config.systemAnnouncement || {},
        getLoginConfig: (state) => state.config.login || {},
        getQrcodeConfig: (state) => state.config.qrcode || {},
        getAdminUrl: (state) => state.config.admin_url,
        getIsShowVip: (state) => !!state.config.memberPackageStatus || false,
        getTabbarConfig: (state) => state.config.tabbar || {},
        getDrawConfig: (state) => state.config.draw || {},
        getPcPageConfig: (state) => state.config.pcChannel || {},
        getIsShowRecharge: (state) =>
            state.config.rechargePackageStatus || false,
        getIsShowMember: (state) => state.config.memberPackageStatus || false,
        getDrawSquareConfig: (state) => state.config.square || {},
        getMindMapConfig: (state) => state.config.mindmap || {},
        getIsVoiceOpen: (state) => !!state.config.voice?.is_open || false
    },
    actions: {
        getImageUrl(url: string) {
            return url.indexOf('http') ? `${this.config.domain}${url}` : url
        },
        async getConfig() {
            const config = await getConfig({ type: 2 })
            const res = await getdecorate({ type: 20 })
            this.bg = JSON.parse(res.pages)[0]
            this.config = config
        }
    }
})
